<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\model\Assets;
use app\common\tool\Result;
use think\facade\View;
use think\response\Json;
use app\common\model\Remit as RemitModel;
use think\exception\ValidateException;

class Remit extends Base
{

    /**
     * post: 充值参数
     * path: remit_account
     * method: remit_account
     */
    public function remit_account()
    {
        $data['remit_min'] = cache('system')['remit_min'];
//        $data['remit_bs'] = cache('system')['remit_bs'];
//        $data['remit_open'] = cache('system')['remit_open'];
        $data['remit_img'] = cache('system')['remit_img'];
        $data['remit_fd'] = cache('system')['remit_fd'];
        $data['balance'] = Assets::where('uid',$this->user->id)->value('balance');
        return Result::success('获取成功',$data);
    }


    public function getList(): Json
    {
        $param = $this->request->param();

        $map = ['uid' => $this->user->id, 'is_del' => 0];

        return json(RemitModel::getPageList($map, 'id,account,amount,create_time,describe,status,reject_msg,pay_way', $param['page'], 20, false));
    }



    /**
     * post: 充值申请
     * path: save
     * method: save
     * param: amount - {string} 充值金额
     */
    public function save()
    {

        $param = $this->request->post();
        if($this->user->is_lock)
        {
            return Result::fail('账号已锁定');
        }
        try {
            $this->validate($param, 'Remit');
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        }
        return json(RemitModel::add($param, $this->user, $this->system));
    }

}

